home *** CD-ROM | disk | FTP | other *** search
- /********************************/
- /* File: FullPathName.c */
- /* */
- /* Given the name and working */
- /* directory of a file, walk the*/
- /* directory tree to determine */
- /* what the full pathname of the*/
- /* directory is... */
- /* */
- /* Paramters: */
- /* param0 = file name num */
- /* param1 = directory id */
- /* */
- /* Out: */
- /* full pathname of the working */
- /* directory */
- /* ---------------------------- */
- /* Once again, I am indepbted to*/
- /* Steve Maller of Apple */
- /* Computer Inc for illuminating*/
- /* this oft too dark realm of */
- /* the toolbox. */
- /********************************/
-
- #include <MacTypes.h>
- #include <OSUtil.h>
- #include <MemoryMgr.h>
- #include <FileMgr.h>
- #include <ResourceMgr.h>
- #include <pascal.h>
- #include <strings.h>
- #include <hfs.h>
- #include "HyperXCmd.h"
- #include "HyperUtils.h"
-
- #define nil 0L
-
- char colon[2] = "\p:";
-
- void ClimbTree( child, cpb, fullName )
- long child;
- CInfoPBPtr cpb;
- char *fullName;
- /*************************
- * Climb the directory tree
- * until we reach the root
- *
- * Allocate the records in the
- * heap to keep the stack frame
- * as small as necessary. Too
- * large a stack frame can
- * lead to a case of terminal
- * terminal.
- *
- * child is the working directory
- * id of the "current folder", vol
- * is the volume reference number and
- * fullName points to the
- * output string
- *************************/
- {
- StringPtr folder_name = (StringPtr)NewPtr( 256 );
-
- /*** setting the file directory index to -1 ***/
- /*** lets us get information about the ***/
- /*** directory whose id is specified in the ***/
- /*** ioDrDIrID field of the parameter block ***/
- folder_name[0] = '\0';
-
- cpb->dirInfo.ioNamePtr = (StringPtr)folder_name;
- cpb->dirInfo.ioDrDirID = child;
-
- if( PBGetCatInfo( cpb, 0) == noErr ){
- ClimbTree(cpb->dirInfo.ioDrParID,cpb,fullName);
-
- Concat( (char *)fullName, (char *)folder_name );
- Concat( (char *)fullName, (char *)&colon );
- }
- DisposPtr( folder_name );
-
- }
-
-
- pascal void main( paramPtr )
- XCmdBlockPtr paramPtr;
- {
- Str31 str,fName;
- short wdid;
- WDPBRec theWDPB;
- CInfoPBRec theCPB;
- HParamBlockRec theHPB;
- char fullPath[256];
- char part_Name[256]; /*** used in HPB ***/
- char vol_Name[256];
- OSErr err;
-
- colon[0] = 1;
- colon[1] = ':';
-
- vol_Name[0] = '\0';
- part_Name[0]= '\0';
- /*** empty is the default answer ***/
- paramPtr->returnValue = 0L;
-
- HLock( paramPtr->params[0] );
- ZeroToPas( paramPtr, *(paramPtr->params[0]), &fName );
- HUnlock( paramPtr->params[0] );
-
- /*** convert the wdid to a usable form ***/
- HLock( paramPtr->params[1] );
- ZeroToPas( paramPtr, *(paramPtr->params[1]), &str );
- HUnlock( paramPtr->params[1] );
- wdid = StrToNum( paramPtr, &str );
-
- /*** First, we appeal to GetVInfo to get ***/
- /*** the volume name that the file lives on ***/
- part_Name[0] = '\0';
- theHPB.volumeParam.ioNamePtr = (StringPtr)vol_Name;
- theHPB.volumeParam.ioVRefNum = (short)wdid;
- theHPB.volumeParam.ioVolIndex = 0;
- if(PBHGetVInfo( &theHPB, 0) != noErr )
- return;
-
- /*** Next, use the working directory info ***/
- /*** to walk the directory tree backwards ***/
- /*** to the root directory ***/
- theWDPB.ioNamePtr = (StringPtr)part_Name;
- theWDPB.ioVRefNum = wdid;
- theWDPB.ioWDProcID = 0;
- theWDPB.ioWDIndex = 0;
- if( PBGetWDInfo( &theWDPB, 0) != noErr )
- return;
-
- fullPath[0] = '\0';
- theCPB.dirInfo.ioFDirIndex = -1;
- theCPB.dirInfo.ioVRefNum = theHPB.volumeParam.ioVRefNum;
-
- ClimbTree( theWDPB.ioWDDirID,
- (CInfoPBPtr)&theCPB,
- (StringPtr)fullPath );
-
- /*** Climbing the tree yields the names of ***/
- /*** all the folders which we still need to ***/
- /*** add the file's name to. ***/
- Concat( (char *)fullPath, (char *)&fName );
-
- paramPtr->returnValue = PasToZero( paramPtr, fullPath );
- }
-
-